package test28;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ws
 * Date: 2023-04-20
 * Time: 21:20
 */
import java.io.*;

//https://www.nowcoder.com/questionTerminal/f11155006f154419b0bef6de8918aea2
public class Main {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintStream out = new PrintStream(new BufferedOutputStream(System.out), true);

    static class Node {
        int val;
        Node next;

        public Node(int val) {
            this.val = val;
        }
    }
    public static void main(String[] args) throws IOException {
        int n = Integer.parseInt(br.readLine());
        String nodeValue = br.readLine();
        String[] nodes = nodeValue.split(" ");
        Node dummyHead = new Node(-1);
        Node tail = dummyHead;
        for (int i = 0; i < n; i++) {
            Node node = new Node(Integer.parseInt(nodes[i]));
            tail.next = node;
            tail = node;
        }
        String part = br.readLine();
        int left = Integer.parseInt(part.split(" ")[0]);
        int right = Integer.parseInt(part.split(" ")[1]);
        Node newHead = reversePartList(dummyHead, left, right);
        while (newHead != null)  {
            out.print(newHead.val + " ");
            newHead = newHead.next;
        }

    }

    private static Node reversePartList(Node head, int left, int right) {
        Node prev = head;
        // 找到前驱节点
        for (int i = 1; i < left; i++) {
            prev = prev.next;
        }
        // 当前节点
        Node cur = prev.next;
        // https://leetcode.cn/problems/reverse-linked-list-ii/description/
        // 反转部分链表，原题
        // 开始反转
        for (int i = left; i < right; i++) {
            Node third = cur.next;
            cur.next = third.next;
            third.next = prev.next;
            prev.next = third;
        }
        return head.next;
    }
}
